<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!--移动端设置viewport-->
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0">
    <!--引入公共样式-->
    <link rel="stylesheet" href="./css/base.css">
    <link rel="stylesheet" href="./css/index.css">
    <!--引入首页的js文件-->
    <!--<script src="./js/index.js"></script>-->
    <!--<script src="./zepto-master/src/zepto.min.js"></script>
    &lt;!&ndash;为了支持和jq类似的选择器，得引入一个新的js文件&ndash;&gt;
    <script src="./zepto-master/src/selector.js"></script>
    <script src="./zepto-master/src/fx.js"></script>
    <script src="./zepto-master/src/touch.js"></script>-->

    <!--引入定制之后的js文件-->
    <script src="./js/zepto.min.js"></script>
    <title>京东-首页</title>
</head>
<body>
<div class="jd_layout">
    <!--搜索块-->
    <div class="jd_search">
        <a href="javascript:;" class="jd_logo"></a>
        <form action="" class="jd_searchBox">
            <!--<span></span>-->
            <input type="text" placeholder="请输入商品名称">
        </form>
        <a href="javascript:;" class="jd_login">登录</a>
    </div>
    <!--轮播图-->
    <div class="jd_banner">
        <!--图片-->
        <ul class="jd_bannerImg clearfix">
            <li>
                <a href="javascript:;">
                    <img src="./uploads/l1.jpg" alt="">
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./uploads/l2.jpg" alt="">
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./uploads/l3.jpg" alt="">
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./uploads/l4.jpg" alt="">
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./uploads/l5.jpg" alt="">
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./uploads/l6.jpg" alt="">
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./uploads/l7.jpg" alt="">
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./uploads/l8.jpg" alt="">
                </a>
            </li>
        </ul>
        <!--点标记-->
        <ul class="jd_bannerIndicator">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <!--导航块-->
    <div class="jd_nav">
        <ul class="clearfix">
            <li>
                <a href="javascript:;">
                    <img src="./images/nav_1.png" alt="">
                    <p>商品分类</p>
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./images/nav_2.png" alt="">
                    <p>商品分类</p>
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./images/nav_3.png" alt="">
                    <p>商品分类</p>
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./images/nav_4.png" alt="">
                    <p>商品分类</p>
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./images/nav_5.png" alt="">
                    <p>商品分类</p>
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./images/nav_6.png" alt="">
                    <p>商品分类</p>
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./images/nav_7.png" alt="">
                    <p>商品分类</p>
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <img src="./images/nav_8.png" alt="">
                    <p>商品分类</p>
                </a>
            </li>
        </ul>
    </div>
    <!--产品块-->
    <div class="jd_product">
        <div class="jd_productBox clearfix jd_sk">
            <div class="jd_pTip">
                <div class="jd_left f_left">
                    <span class="jd_sk_icon f_left m_left10"></span>
                    <span class="jd_sk_text f_left m_left10">掌上秒杀</span>
                    <div class="jd_sk_time f_left m_left10">
                        <span>0</span>
                        <span>0</span>
                        <span>:</span>
                        <span>0</span>
                        <span>0</span>
                        <span>:</span>
                        <span>0</span>
                        <span>0</span>
                    </div>
                </div>
                <div class="jd_right f_right m_right10">更多秒杀...</div>
            </div>
            <div class="jd_pContent clearfix">
                <ul>
                    <li>
                        <a href="javsscript:;">
                            <img src="./uploads/detail01.jpg" alt="">
                        </a>
                        <p>&yen;10.00</p>
                        <p>&yen;20.00</p>
                    </li>
                    <li>
                        <a href="javsscript:;">
                            <img src="./uploads/detail01.jpg" alt="">
                        </a>
                        <p>&yen;10.00</p>
                        <p>&yen;20.00</p>
                    </li>
                    <li>
                        <a href="javsscript:;">
                            <img src="./uploads/detail01.jpg" alt="">
                        </a>
                        <p>&yen;10.00</p>
                        <p>&yen;20.00</p>
                    </li>
                </ul>
            </div>
        </div>
        <div class="jd_productBox">
            <div class="jd_pTip">
                <h3>京东超市</h3>
            </div>
            <div class="jd_pContent clearfix">
                <a href="javascript:;" class="a_50 f_left">
                    <img src="./uploads/cp1.jpg" alt="">
                </a>
                <a href="javascript:;" class="a_50 f_left b_bottom b_left">
                    <img src="./uploads/cp2.jpg" alt="">
                </a>
                <a href="javascript:;" class="a_50 f_left b_left">
                    <img src="./uploads/cp3.jpg" alt="">
                </a>
            </div>
        </div>
        <div class="jd_productBox">
            <div class="jd_pTip">
                <h3>京东超市</h3>
            </div>
            <div class="jd_pContent clearfix">
                <a href="javascript:;" class="a_50 f_right">
                    <img src="./uploads/cp4.jpg" alt="">
                </a>
                <a href="javascript:;" class="a_50 f_left b_bottom b_left">
                    <img src="./uploads/cp5.jpg" alt="">
                </a>
                <a href="javascript:;" class="a_50 f_left b_left">
                    <img src="./uploads/cp6.jpg" alt="">
                </a>
            </div>
        </div>
        <div class="jd_productBox">
            <div class="jd_pTip">
                <h3>京东超市</h3>
            </div>
            <div class="jd_pContent clearfix">
                <a href="javascript:;" class="a_50 f_left">
                    <img src="./uploads/cp1.jpg" alt="">
                </a>
                <a href="javascript:;" class="a_50 f_left b_bottom b_left">
                    <img src="./uploads/cp2.jpg" alt="">
                </a>
                <a href="javascript:;" class="a_50 f_left b_left">
                    <img src="./uploads/cp3.jpg" alt="">
                </a>
            </div>
        </div>
    </div>
</div>
<script>
    /*使用zepto实现轮播图*/
    $(function(){
        /*1.添加首尾两张图片*/
        /*2.重新设置图片盒子的宽度和图片的宽度*/
        /*3.开启定时器，实现自动轮播*/
        /*4.添加移动端的滑动事件，实现手动轮播*/
        /*5.添加过渡效果结束之后的监听*/
        /*获取轮播图元素*/
        var banner = $(".jd_banner")
        var bannerWidth = banner.width();       
        /*获取图片盒子*/
        var imgBox = banner.find("ul:first-of-type");
        /*获取点标记*/
        var indicators = banner.find("ul:eq(1)").find("li");
        /*获取首尾两张图片*/
        var first = imgBox.find("li:first-of-type");
        var last = imgBox.find("li:last-of-type");       
        /*将两张图片添加到首尾位置  first.clone():将first复制一份*/
        imgBox.append(first.clone());
        last.clone().insertBefore(first);

        /*设置图片盒子的宽度*/
        var lis = imgBox.find("li");   
        var count = lis.length;
        imgBox.width(count*bannerWidth); 
        /*设置li标签的宽度*/
        $.each(lis,function(index,value){
            $(lis[index]).width(bannerWidth);
            console.log(index);
        });
        /*设置默认偏移*/
        imgBox.css("left",-bannerWidth);
        /*定义图片索引*/
        var index = 1;

         /*图片轮播的动画效果*/
        var imgAnimation = function(){
            imgBox.animate(
                {"left":-index*bannerWidth},
                200,
                "ease-in-out",
                function(){//动画执行完毕之后的回调
                     /*判断当前索引位置是否是最后一张或者第一张*/
                     if(index == count-1){
                         index = 1;
                         /*让它瞬间偏移到索引1的位置--非过渡*/
                         imgBox.css("left",-index*bannerWidth);
                     }
                     else if(index == 0){//最后一张
                         index = count-2;
                         imgBox.css("left",-index*bannerWidth);
                     }  
                    /*设置点标记*/
                    indicators.removeClass("active").eq(index-1).addClass("active");
                }

            )
        }
                
                   
                   

        /*开启定时器*/
        var timerId = setInterval(function(){
            index++;
            /*开启过渡*/
            /*设置定位*/
            /*在zepto中直接使用animate函数来实现
            * 1.需要添加动画效果的样式--对象
            * 2.动画的耗时
            * 3.动画的速度函数 animation-timing-function
            * 4.当前动画执行完毕之后的回调*/
            imgAnimation();
        },2000)
           
          
                        
        /*添加滑动事件*/
        /*左滑动*/
        /*在谷歌浏览器的模拟器中，无法正确的触发swipe相关事件，但是可以触发tap事件*/
        imgBox.on("swipeLeft",function(){
            clearInterval(timerId);
            index++;
            imgAnimation();
            console.log("swipeLeft");
        })
        /*右滑动*/
        imgBox.on("swipeRight",function(){
            clearInterval(timerId);
            index--;
            imgAnimation();
            console.log("swipeRight");
        })
       
    });
   
        
        
        
        
        
        
        
        
        
        
      

        
       
        
        
        
        

       
                       

        
        
</script>
</body>
</html>